<?php
	header ('Access-Control-Allow-Origin: *');
	header ('Access-Control-Allow-Methods: POST');
	
	include_once ('function/function.php');
	include_once ('function/conn.php');

	function updateHistory($uid, $bid, $article_id, $article_title) {
		$result_history = false;
		$returnObject = array();

		if (!$uid || empty($uid)) {
			$returnObject = (object) array(
				"error_code" => 2000,
				"error_msg" => "参数错误：uid不能为空",
			);

			return $returnObject;
		}

		if (!$bid || empty($bid)) {
			$returnObject = (object) array(
				"error_code" => 2001,
				"error_msg" => "参数错误：bid不能为空",
			);

			return $returnObject;
		}

		if (!$article_id || empty($article_id)) {
			$returnObject = (object) array(
				"error_code" => 2006,
				"error_msg" => "参数错误：article_id不能为空",
			);

			return $returnObject;
		}

		if (!$article_title || empty($article_title)) {
			$returnObject = (object) array(
				"error_code" => 2007,
				"error_msg" => "参数错误：article_title不能为空",
			);

			return $returnObject;
		}

		$result = mysql_query("select * from `book-lite_history` where bid='$bid' and uid='$uid' limit 1");

		if (mysql_num_rows($result)) {
			mysql_query("update `book-lite_history` set article_id='$article_id', article_title='$article_title' where bid='$bid' and uid='$uid' limit 1");
		} else {
			mysql_query("insert into `book-lite_history` (bid, article_title, article_id, uid) values ('$bid', '$article_title', '$article_id', '$uid')");
		}

		mysql_query("update `book-lite_list` set last_read=CURRENT_TIMESTAMP where bid='$bid' and uid='$uid' limit 1");
		
		mysql_free_result($result);

		$returnObject = array(
			"result" => true,
		);

		return $returnObject;
	}
?>